class NanxingDbRouter:
    """
    A router to control all database operations on models in the
    'nanxing_db' application.
    """

    def db_for_read(self, model, **hints):
        """
        Attempts to read nanxing models go to nanxing_db.
        """
        if model._meta.app_label == 'nanxing_app':  # 用您的应用标签替换 'nanxing_app'
            return 'nanxing_db'
        return 'default'

    def db_for_write(self, model, **hints):
        """
        Attempts to write nanxing models go to nanxing_db.
        """
        if model._meta.app_label == 'nanxing_app':  # 用您的应用标签替换 'nanxing_app'
            return 'nanxing_db'
        return 'default'

    def allow_relation(self, obj1, obj2, **hints):
        """
        Allow relations if a model in the nanxing app is involved.
        """
        if obj1._meta.app_label == 'nanxing_app' or \
           obj2._meta.app_label == 'nanxing_app':
            return True
        return None

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        """
        Make sure the nanxing app only appears in the 'nanxing_db'
        database.
        """
        if app_label == 'nanxing_app':
            return db == 'nanxing_db'
        return None
